package utils;

import java.util.ArrayList;

public class Vertex {
	private double x,y,z;
	private int index; 
	static private int count=0;
	static public ArrayList<Vertex> dejaVU=new ArrayList<Vertex>();

	public Vertex(double x, double y, double z) {
		super();
		this.x = x;
		this.y = y;
		this.z = z;
		this.index=count++;
		dejaVU.add(this);
	}

	/**
	 * @return the index
	 */
	public int getIndex() {
		return index;
	}

	/**
	 * @return the x
	 */
	public double getX() {
		return x;
	}

	/**
	 * @return the y
	 */
	public double getY() {
		return y;
	}

	/**
	 * @return the z
	 */
	public double getZ() {
		return z;
	} 
	public String toString(){
		return "<"+x+","+y+","+z+">"; 
	}
	
	public boolean equals(Object o){
		 if (!(o instanceof Vertex)) return false; 
		 Vertex vo=(Vertex)o; 
		 if(Math.abs(this.x-vo.x)>1e-6) return false; 
		 if(Math.abs(this.y-vo.y)>1e-6) return false; 
		 if(Math.abs(this.z-vo.z)>1e-6) return false; 
		 return true; 
	}
	
	public static int dejavu(double x,double y,double z){
		for(Vertex cv:dejaVU){
			 if((Math.abs(cv.x-x)<1e-6) 
			 &&(Math.abs(cv.y-y)<1e-6) 
			 &&(Math.abs(cv.z-z)<1e-6)) return cv.getIndex();
		}
		return -1; 
	}
	

}
